package cn.wolfcode.util;

import cn.wolfcode.domain.Employee;
import org.apache.shiro.SecurityUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;


import javax.servlet.http.HttpSession;
import java.util.List;

public class UserContext {

    //public static final String USER_IN_SESSION = "USER_IN_SESSION";
    //public static final String PERMISSION_IN_SESSION = "PERMISSION_IN_SESSION";

    /**
     * 获取session对象
     * @return
     *//*
    public static HttpSession getSession(){
        //springmvc提供的工具,可以在任意地方获取到request对象,response对象,session对象
        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        return servletRequestAttributes.getRequest().getSession();
    }*/

    /**
     * 从session中获取当前登录用户
     * @return
     */
    public static  Employee getCurrentUser(){
        return (Employee) SecurityUtils.getSubject().getPrincipal();
    }

    /**
     * 设置用户对象到session中
     * @param employee
     *//*
    public static void setCurrentUser(Employee employee){
        getSession().setAttribute(USER_IN_SESSION,employee);
    }

    *//**
     * 从session中获取当前登录用户的权限
     * @return
     *//*
    public static List<String> getPermission(){
        return (List<String>) getSession().getAttribute(PERMISSION_IN_SESSION);
    }

    *//**
     * 设置权限到session中
     * @param list
     *//*
    public static void setPermission(List<String> list){
        getSession().setAttribute(PERMISSION_IN_SESSION,list);
    }*/
}
